import request from '@/utils/request'
import type {
  KnowledgeListPage,
  KnowledgeType,
  DoctorPage,
  FollowType,
  TopDep,
  Image,
  ConsultOrderPreParams,
  ConsultOrderPreData,
  PartialConsult,
  ConsultOrderItem,
  ConsultOrderListPageParams,
  ConsultOrderList,
} from '@/types/consult'
import type { Patient } from '@/types/user'
import type { EvaluateDocParams } from '@/types/room'

/**
 * 首页-查询推荐/减脂/饮食健康/关注页面--百科文章列表
 * @param param0
 * @returns
 */
export const getKnowledgeListService = ({
  type,
  pageSize,
  current,
}: {
  type: KnowledgeType
  pageSize: number
  current: number
}) => {
  return request.get<KnowledgeListPage>('/patient/home/knowledge', {
    params: {
      type,
      pageSize,
      current,
    },
  })
}

/**
 * 首页-查询推荐医生列表
 * @param param0
 * @returns
 */
export const getRecommendDoctorService = ({
  current,
  pageSize,
}: {
  current: number
  pageSize: number
}) => {
  return request.get<DoctorPage>(`/home/page/doc?current=${current}&pageSize=${pageSize}`)
}

/**
 * 关注/取消关注医生/百科/话题/疾病
 * @param id
 * @param type
 * @returns
 */
export const followService = (id: string, type: FollowType = 'doc') => {
  return request.post('/like', { id, type })
}

// 获取所有科室
export const getDepsService = () => {
  return request.get<TopDep>('/dep/all')
}

/**
 * 上传文件、图片
 *
 */
export const uploadFileService = (file: File) => {
  const fd = new FormData()
  // 说明：formData对象的key属性值后台定义
  fd.append('file', file)
  return request.post<Image>('/upload', fd)
}

/**
 * 问诊订单预支付
 * @param params
 * @returns
 */
export const getConsultOrderPreService = (params: ConsultOrderPreParams) => {
  return request.get<ConsultOrderPreData>('/patient/consult/order/pre', {
    params,
  })
}

/**
 * 获取患者详情
 */
export const getPatientInfoService = (id: string) => {
  return request.get<Patient>('/patient/info/' + id)
}

/**
 * 保存/修改问诊订单
 */
export const submitConsultOrderService = (data: PartialConsult) => {
  return request.post<{ id: string }>('/patient/consult/order', data)
}

// 获取支付地址  0 是微信  1 支付宝
export const getConsultOrderPayUrl = (data: {
  paymentMethod: 0 | 1
  orderId: string
  payCallback: string
}) => request.post<{ payUrl: string }>('/patient/consult/pay', data)

/**
 * 获取问诊订单详情
 */
export const getConsultOrderDetailService = (id: string) => {
  return request.get<ConsultOrderItem>('/patient/consult/order/detail', {
    params: {
      orderId: id,
    },
  })
}

// 查看处方
export const getPrescriptionPicService = (id: string) =>
  request.get<{ url: string }>(`/patient/consult/prescription/${id}`)

// 评价医生
export const evaluateDoctorService = (data: EvaluateDocParams) => {
  return request.post<{
    id: string // 评价id
  }>('/patient/order/evaluate', data)
}
// 问诊记录列表
export const getConsultOrderListService = (params: ConsultOrderListPageParams) => {
  return request.get<ConsultOrderList>('/patient/consult/order/list', {
    params,
  })
}

// 取消订单
export const cancelConsultOrderService = (id: string) => {
  return request.put(`/patient/order/cancel/${id}`)
}

// 删除订单
export const deleteOrderService = (id: string) => {
  return request.delete(`/patient/order/${id}`)
}
